#!/usr/bin/perl
use strict;
use warnings;

my @entries=();

sub push_entries(){
 my %args=@_;
 my $folder=$args{folder};
 $folder.="/" unless ($folder =~ m/.*\/$/);
 my $file=$args{file};
 foreach my $filename(<$folder$file>){
  next if ($filename =~ m/.*test\.log$/);
  if (-d $filename) {
   push(@entries,"\n#~#FOLDER:$filename#~#\n");
   next;
  }
  push(@entries,"\n#~#$filename#~#\n");
  open(FILE,$filename);
  push(@entries,<FILE>);
  close(FILE);
 }
}

my $nw_folder= ($^O =~ m/MSWin32/) ? 'C:/Legato/nsr' : '/nsr';
my $nw_bin_folder="/usr/sbin";
if ($^O =~ m/MSWin32/) { 
 $nw_bin_folder="$nw_folder/bin";
} elsif ($^O =~ m/linux/) {
 $nw_bin_folder="/usr/sbin";
} else {
 $nw_bin_folder="/usr/bin";
}
my $nw_res_folder="$nw_folder/res";
my $ora_folder= ($^O =~ m/MSWin32/) ? '/oracle/*/*/database' : '/oracle/*/*/dbs';

push(@entries,"\n#~#BOS#~#\n");
&push_entries(folder=>"$nw_res_folder",file=>'*');
&push_entries(folder=>"$nw_folder/sapdb",file=>'*') if (-d "$nw_folder/sapdb");
&push_entries(folder=>"$nw_bin_folder",file=>'nsrnmo_*') if (glob("$nw_bin_folder/nsrnmo_*")) ;
&push_entries(folder=>"$nw_bin_folder",file=>'nsr*_DB*bat') if (glob("$nw_bin_folder/nsr*_DB*bat")) ;
&push_entries(folder=>"$nw_bin_folder",file=>'nsr*_DB*sh') if (glob("$nw_bin_folder/nsr*_DB*sh")) ;
&push_entries(folder=>"$nw_bin_folder",file=>'nsr*_LOG*bat') if (glob("$nw_bin_folder/nsr*_LOG*bat")) ;
&push_entries(folder=>"$nw_bin_folder",file=>'nsr*_LOG*sh') if (glob("$nw_bin_folder/nsr*_LOG*sh")) ;

if ($^O =~ m/MSWin32/) {
 for my $drive ('A'..'Z') {
  my $folder=$drive.":".$ora_folder;
  &push_entries(folder=>$folder,file=>'init*_*') if (-d $folder);
 }
} else {
 &push_entries(folder=>$ora_folder,file=>'init*_*utl');
 &push_entries(folder=>$ora_folder,file=>'init*_*sap');
}
push(@entries,"\n#~#EOS#~#\n");
print STDOUT @entries;